package com.bridgeQQ.client.core
{
	import com.bridgeQQ.client.constant.CommandConst;
	import com.bridgeQQ.client.control.commands.AddFriendCommand;
	import com.bridgeQQ.client.control.commands.AddFriendTypeCommand;
	import com.bridgeQQ.client.control.commands.ChangeFriendTypeCommand;
	import com.bridgeQQ.client.control.commands.DelFriendTypeCommand;
	import com.bridgeQQ.client.control.commands.LogOutCommand;
	import com.bridgeQQ.client.control.commands.RemoteMethodCommand;
	import com.bridgeQQ.client.control.commands.RemoveFriendCommand;
	import com.bridgeQQ.client.control.commands.RequestFriendCommand;
	import com.bridgeQQ.client.control.commands.msg.SendMsgCommand;
	import com.bridgeQQ.client.control.commands.uiinteracte.OpenBridgeMsgWindowCommand;
	import com.bridgeQQ.client.control.commands.uiinteracte.OpenNormalMsgWindowCommand;
	import com.bridgeQQ.client.model.BridgeModel;
	import com.bridgeQQ.client.service.Service;
	
	public class SimpleCommandFactory
	{
		public static function getCommand(service:Service, commandName:String, info:Object):ICommand
		{
			var result:ICommand;
			switch(commandName)
			{
				case CommandConst.REGISTER:
				    result = new RemoteMethodCommand(info, 
                        service.userService.addUser,info.account, info.password);
                    break;
				case CommandConst.LOGIN:
				    result = new RemoteMethodCommand(info, 
				        service.userService.login, info.account, info.password, info.peerID);
				    break;
				case CommandConst.LOGOUT:
				    result = new LogOutCommand(new RemoteMethodCommand(info, service.userService.serverLogout, BridgeModel.instance.user.email));
				    break; 
			    case CommandConst.REQUEST_ADD_FRIEND:
			        result =  new RequestFriendCommand();
			        break;
			    case CommandConst.ADD_FRIEND:
			        result = result = new AddFriendCommand(new RemoteMethodCommand(info, service.userPossessService.addFriendInType, 
			        	    BridgeModel.instance.user.email, info.friend, info.typeID));
			        break;
			    case CommandConst.REPLY_ADD_FRIEND:
			        if(!info.agree)
			        {
			        	result = new SendMsgCommand(info, null);
			        }
			        else
			        {
			        	result = new AddFriendCommand(new RemoteMethodCommand(info, service.userPossessService.addFriendInType, 
			        	    BridgeModel.instance.user.email, info.friend, info.typeID));
			        } 
				    break;
				case CommandConst.ADD_FRIEND_TYPE:
				    var method:Object = info.item.id ? service.friendTypeService.changeName : service.userPossessService.addFriendType;
				    if(info.item.id)
				    {
				    	result = new AddFriendTypeCommand(new RemoteMethodCommand(info, 
				       		method, info.item.id, info.name));
				    }
				    else
				    {
				    	result = new AddFriendTypeCommand(new RemoteMethodCommand(info, 
				       		 method, BridgeModel.instance.user.email, info.name));
				    }   
				    break;
				case CommandConst.DEL_FRIEND_TYPE:
				    result = new DelFriendTypeCommand((new RemoteMethodCommand(info, 
				       		service.userPossessService.removeFriendType, BridgeModel.instance.user.email, info.item.id)));
				    break;
				case CommandConst.REMOVE_FRIEND:
				    result = new RemoveFriendCommand( new RemoteMethodCommand(info, 
				        service.friendTypeService.removeFriend, info.typeID, info.friend));
				    break;
				case CommandConst.CHANGE_USER_FRIEND_TYPE:
				    result = new ChangeFriendTypeCommand(new RemoteMethodCommand(info, service.friendTypeService.changeFriendType,
				        info.friend, info.oldTypeID, info.newTypeID));
				    break;
				case CommandConst.OPEN_NORMAL_MSG:
				    result = new OpenNormalMsgWindowCommand(info, null);
				    break;
				case CommandConst.OPEN_BRIDGE_MSG:
				    result = new OpenBridgeMsgWindowCommand(info, null);
				    break;
				case CommandConst.SEND_MESSAGE:
				    result = new SendMsgCommand(info, null);
				    break;    
			}
			return result;
		}
	}
}